//
//  OrderCell.m
//  DaJiang
//
//  Created by sally on 16/10/6.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "OrderCell.h"

@interface OrderCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (weak, nonatomic) IBOutlet UILabel *topicLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIView *timeView;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIView *addressView;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeViewHeightLyt;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addressViewHeightLyt;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@end

@implementation OrderCell

- (void)awakeFromNib {
  [self initControl];
}

- (void)initControl {
  self.headImage.layer.cornerRadius = self.headImage.height / 2;
  self.headImage.layer.masksToBounds = YES;
}

- (void)setOrderCellType:(OrderCellType)orderCellType {
  _orderCellType = orderCellType;

  //设置数据后，才装配控件
  if (self.orderCellType == OrderCellType_OrderMe) {
    self.timeViewHeightLyt.constant = GNormalViewHeight;
    self.addressViewHeightLyt.constant = GNormalViewHeight;
    self.timeView.hidden = NO;
    self.addressView.hidden = NO;
  } else {
    self.timeViewHeightLyt.constant = 0;
    self.addressViewHeightLyt.constant = 0;
    self.timeView.hidden = YES;
    self.addressView.hidden = YES;
  }
}

- (void)setCellData:(OrderModel *)cellData {
  [self.headImage sd_setImageWithURL:[NSURL URLWithString:cellData.op_data.pro_user_profile_pic] placeholderImage:[UIImage imageNamed:@"ic_default"]];
  self.topicLabel.text = cellData.op_data.pro_topic_name;
  self.nameLabel.text = cellData.op_data.pro_user_name;
  self.statusLabel.text = cellData.op_data.state_detail_desc;
  self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f 约%@", cellData.op_data.pro_topic_price, cellData.pro_topic.data.time_length];
  self.timeLabel.text = [NSString stringWithFormat:@"见面时间：%@", cellData.op_data.meet_time];
  self.addressLabel.text = [NSString stringWithFormat:@"见面地点：%@", cellData.op_data.meet_location];
}

- (void)setCellTopicData:(TopicModel *)cellTopicData {
  [self.headImage sd_setImageWithURL:[NSURL URLWithString:cellTopicData.user.user_data.user_profile_pic] placeholderImage:[UIImage imageNamed:@"ic_default"]];
  self.topicLabel.text = cellTopicData.data.topic_name;
  self.nameLabel.text = cellTopicData.user.user_data.user_name;
  if (cellTopicData.data.avaliable == 0) {
    self.statusLabel.text = @"已上架";
  } else {
    self.statusLabel.text = @"已下线";
  }
  self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f 约%@", cellTopicData.data.topic_price, cellTopicData.data.time_length];
}

@end
